Skip to content

[DowngradePhp84] Add DowngradeExitNamedArgumentRector - #387

Merged
TomasVotruba merged 4 commits into
mainfrom
downgrade-exit
Aug 7, 2026
Merged

[DowngradePhp84] Add DowngradeExitNamedArgumentRector#387
TomasVotruba merged 4 commits into
mainfrom
downgrade-exit

Conversation

@samsonasik

@samsonasik samsonasik commented Aug 7, 2026

Copy link
Copy Markdown
Member

Closes rectorphp/rector#9844

Diff

-exit(status: 1);
+exit(1);

In PHP 8.4, exit or die can be marked as function call with provide named argument status

https://php.watch/versions/8.4/exit-die-as-functions

On downgrade to php 8.3, it currently doesn't remove the named argument

https://getrector.com/demo/ef539935-7ed2-4cc4-9063-dd07681260ba

On usage, it will create error:

https://3v4l.org/f0f3a#v8.3.33

So, the DowngradePhp84 rule is needed for it.

@samsonasik
samsonasik requested a review from TomasVotruba August 7, 2026 10:28
@samsonasik

Copy link
Copy Markdown
Member Author

@TomasVotruba ready 👍

@TomasVotruba
TomasVotruba merged commit 089be4a into main Aug 7, 2026
9 checks passed
@TomasVotruba
TomasVotruba deleted the downgrade-exit branch August 7, 2026 11:48
@TomasVotruba

Copy link
Copy Markdown
Member

LGTM 👍 Probably all named args in native functions should be downgraded, not just exit()

@samsonasik

Copy link
Copy Markdown
Member Author

That's special on exit/die only for php 8.4.

Other downgrade named argument is on DowngradePhp80 DowngradeNamedArgumentRector

final class DowngradeNamedArgumentRector extends AbstractRector

@TomasVotruba

Copy link
Copy Markdown
Member

The DowngradeNamedArgumentRector should handle the exit() as well

@TomasVotruba

Copy link
Copy Markdown
Member

Why this doesn't worK? https://3v4l.org/f0f3a#v8.3.33
Weird :D

@samsonasik

samsonasik commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

that's "Process exited with code 1" means works on php 8.4, the page shows 2 part,

php 8.4: Process exited with code 1.
php 8.3: syntax error, unexpected token ":", expecting ")"

see https://php.watch/versions/8.4/exit-die-as-functions

the transformation is remove the identifier status.

@samsonasik

Copy link
Copy Markdown
Member Author

DowngradeNamedArgumentRector will automatically handle exit(status: 1), but if user only want to downgrade to php 8.3, it will not catch without this rule.

The downgrade process is from top to bottom, if I want to downgrade to php 8.3 only, this take care of it.

The original node is Expr\Exit_ https://github.com/nikic/PHP-Parser/blob/fbd47f7ebcbb450138d92642a0a53b72a5285dda/lib/PhpParser/Node/Expr/Exit_.php#L7

but start from php 8.4, it can be any function call with status named arg https://github.com/nikic/PHP-Parser/blob/fbd47f7ebcbb450138d92642a0a53b72a5285dda/lib/PhpParser/Node/Expr/FuncCall.php#L8

@TomasVotruba

Copy link
Copy Markdown
Member

I see, so PHP 8.4 switched from exit type to normal function. Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[DowngradePhp84] Downgrade exit/die with named argument

2 participants